package com.rr.sort;

import java.util.Arrays;

/**
 * @author RR
 * @date 2022/12/28 13:17
 */
public class SelectSort {
    public static void selectSort(int[] array) {
        int length = array.length;
        for (int i = 0; i < length - 1; i++) {
            int minIndex = i;
            for (int j = i + 1; j < length; j++) {
                if (array[j] < array[minIndex]) {
                    minIndex = j;
                }
            }
            // i和minIndex交换
            int temp = array[i];
            array[i] = array[minIndex];
            array[minIndex] = temp;
        }
    }

    public static void main(String[] args) {
        int[] array = new int[]{5, 4, 3, 2, 1};
        selectSort(array);
        System.out.println(Arrays.toString(array));
    }
}
